import request from '@/utils/request'

export function fetchList(query) {
  return request({
    url: '/api/getEmployeeByPage',
    method: 'get',
    params: query
  })
}

export function downloadEmp() {
  return request({
    url: '/api/getEmployee',
    method: 'get',
  })
}

export function addEmp(data) {
  return request({
    url: '/api/addEmp',
    method: 'post',
    data
  })
}

export function updateEmployee(data) {
  return request({
    url: '/api/updateEmployee',
    method: 'post',
    data
  })
}

export function getDept(query){
  return request({
    url: '/api/getDept',
    method: 'get',
    params: query
  })
}

//删除
export function delEmpAndDept(empId) {
  return request({
      url: '/api/deleteEmpAndDept/' + empId,
      method: 'delete',
  })
}

export function getEmpAndDept(listQuery,searchList){
  // 构建动态的params对象
  const params = Object.assign(
    {
      pageNum: listQuery.pageNum,
      pageSize: listQuery.pageSize,
      // 其他默认条件
    },
    // 只添加有值的查询条件 条件可为空
    searchList.empName && { empName: searchList.empName },
    searchList.deptId && { deptId: searchList.deptId },
    searchList.empDegreeName && { empDegreeName: searchList.empDegreeName }

  );
  return request({
    url: '/api/getEmpAndDept',
    method: 'get',
    params: params,
  })
}
